 //============= RECEIVE OSC COMMANDS =========================

// Notes on the message protocol:
// * Top address is either a command for all spots, or the spot indicator ("spot1", "spot2"...)
// * The address[1] define the variable or mode to change (see soundSpot for sound-sending variables).
//   Some of these take VALUES.
// Example of a message: 
//     "/spot2/SendOSCMode/1" means start sending automatically in OSC mode
//     "/spot2/sendingPosition/1" means sending position (in any active mode). 


void processOSC() {
  
  // for tests:
   logMessage(&recMes);

  // acquire the addresses and arguments:
  strcpy(address[0],""); strcpy(address[1],"");
  for (int i=0; i<recMes.getAddressNum(); i++)  strcpy(address[i],recMes.getAddress(i)); // NOTE: up to the rest of the program to check if address[1] is really not null
  // acquire data:
  data[0]=-1;  data[1]=-1; 
  for (int i=0; i<recMes.getArgNum(); i++) data[i]=(int)recMes.getArgInt(i);
  
 interpretCommand();//address, data);
}


// FOR TESTS ONLY (using the Serial port): 
void logMessage(OSCMessage *mes) {
  
    uint8_t *ip=mes->getIp();
  
    Serial.println(" ");
     //disp ip & port
    Serial.print("from IP:");
    Serial.print(ip[0],DEC);
    Serial.print(".");
    Serial.print(ip[1],DEC);
    Serial.print(".");
    Serial.print(ip[2],DEC);
    Serial.print(".");
    Serial.print(ip[3],DEC);
    Serial.print(" port:");
    Serial.print(mes->getPort(),DEC);
    Serial.print("   ");
    
    //disp adr
    for(int i = 0 ; i < mes->getAddressNum() ; i++){
      
      Serial.print(mes->getAddress(i));
       Serial.print(" ");
      
    }
    
    
    //disp type tags
    Serial.print("  ,");
    for(int i = 0 ; i < mes->getArgNum() ; i++){
      
      Serial.print(mes->getTypeTag(i));
      
    }
    Serial.print(" ");
   
   
   //disp args
    for(int i = 0 ; i < mes->getArgNum() ; i++){
      
      switch( mes->getTypeTag(i) ){
        
        case 'i': {
                      
                      Serial.print( mes->getArgInt(i) );
                  }
          break;
        
        case 'f':  {
                      
                      Serial.print( mes->getArgFloat(i) );
                  }
          break;
         
      }
      
       Serial.print(" ");
      
    }
    
    Serial.println(""); 
    
}

